﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 享元模式
{
    /// <summary>
    /// 1  建立一个享元模式（Flyweight）
    /// 2  和单例模式的区别
    /// 3  享元模式在.net里面的应用
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //Show();
                //Show1();

                new Action(Show).BeginInvoke(null,null);
                new Action(Show1).BeginInvoke(null, null);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            Console.Read();
        }

        //private static BaseWord e1 = new E();
        //private static BaseWord l = new L();
        //private static BaseWord v = new V();
        //private static BaseWord n = new N();
        private static void Show()
        {
            BaseWord e1 = FlyweightFactory.GetWord(WordType.E);
            BaseWord l = FlyweightFactory.GetWord(WordType.L);
            //BaseWord e2 = new E();
            BaseWord v = FlyweightFactory.GetWord(WordType.V);
            //BaseWord e3 = new E();
            BaseWord n = FlyweightFactory.GetWord(WordType.N);

            Console.WriteLine($"{e1.Display()}{l.Display()}{e1.Display()}{v.Display()}{e1.Display()}{n.Display()}");
        }

        private static void Show1()
        {
            BaseWord e1 = FlyweightFactory.GetWord(WordType.E);
            BaseWord l = FlyweightFactory.GetWord(WordType.L);
            //BaseWord e2 = new E();
            BaseWord v = FlyweightFactory.GetWord(WordType.V);
            //BaseWord e3 = new E();
            BaseWord n = FlyweightFactory.GetWord(WordType.N);
            Console.WriteLine($"{e1.Display()}{l.Display()}{e1.Display()}{v.Display()}{e1.Display()}{n.Display()}");
        }
    }
}
